﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TruongVu.Data;

namespace TruongVu.Business
{
    public class AboutUsModel
    {
        public IList<AboutUs> GetHomeList()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 1
                        select about).ToList();
            return data;
        }

        public IList<AboutUs> GetCompanyInfoList() 
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 2
                        select about).ToList();
            return data;
        }

        public IList<AboutUs> GetCompanyOfficeList()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 3
                        select about).ToList();
            return data;
        }

        public IList<AboutUs> GetCompanyFoundingBoardList()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 4
                        select about).ToList();
            return data;
        }

        public AboutUs GetHomeInfo()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 1
                         select about).SingleOrDefault();
            return data;
        }
        
        public AboutUs GetCompanyInfo()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 2
                        select about).SingleOrDefault();
            return data;
        }

        public AboutUs GetCompanyOffice()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 3
                        select about).SingleOrDefault();
            return data;
        }

        public AboutUs GetCompanyFoundingBoard()
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == 4
                        select about).SingleOrDefault();
            return data;
        }

        public void ModifyAboutUs(int id, string description)
        {
            var data = (from about in Singleton.DataContext.AboutUs
                        where about.ID == id
                        select about).SingleOrDefault();
            if (data != null)
            {
                data.Description = description;
            }
            else
            {
                data = new AboutUs();
                data.ID = id;
                data.Description = description;
                Singleton.DataContext.AboutUs.InsertOnSubmit(data);
            }

            Singleton.DataContext.SubmitChanges();
        }
    }
}
